import http from '../../api/http.js'
import { requestData } from '../../common/js/commont.js'
// 获取点位信息
const getMapinfoSD = (data) => http.post('/api/map/getMapInfo', requestData(data))
// 获取历史数据曲线用
const getHistorydeviceLogSD = (data) => http.post('/api/Devicelog/getHistoryDeviceLog', requestData(data))
// 获取用户设备接收参数
const getDeviceParamsSD = (data) => http.post('/api/device/getDeviceParams', requestData(data))
// 获取设备数据列表
const getDeviceLogListSD = (data) => http.post('/api/device/getDeviceLogList', requestData(data))
// 获取地区列表下的国控空气站
const getAreaListSD = (data) => http.post('/api/area/getAreaList', requestData(data))

const modules = {
  state: {
    User: null,
    MapInfoSD: null,
    HistorydeviceLogSD: null,
    DeviceParamsSD: null,
    DeviceLogListSD: null,
    AreaListSD: null,
    Eparam: null,
    DataTable: null,
    SelectedTable: null
  },
  mutations: {
    setMapInfoSD (state, data) {
      state.MapInfoSD = data
    },
    setHistorydeviceLogSD (state, data) {
      state.HistorydeviceLogSD = data
    },
    setDeviceParamsSD (state, data) {
      state.DeviceParamsSD = data
    },
    setDeviceLogListSD (state, data) {
      state.DeviceLogListSD = data
    },
    setAreaListSD (state, data) {
      state.AreaListSD = data
    },
    updateEparam (state, data) {
      const arr = []
      data.map((item) => {
        arr.push(item.name)
      })
      state.Eparam = arr.join(',')
    },
    updateDataTable (state, data) {
      state.DataTable = data
    },
    updateSelectedTable (state, data) {
      state.SelectedTable = data
    }
  },
  actions: {
    async getMapInfoSD ({ commit }, data) {
      try {
        var res = await getMapinfoSD(data)
        commit('setMapInfoSD', res.data.data)
        return res
      } catch (e) {
        throw new Error(e)
      }
    },
    async getHistoryDeviceLogSD ({ commit }, data) {
      try {
        var res = await getHistorydeviceLogSD(data)
        commit('setHistorydeviceLogSD', res.data.data)
        return res
      } catch (e) {
        throw new Error(e)
      }
    },
    async getDeviceParamsSD ({ commit }, data) {
      try {
        var res = await getDeviceParamsSD(data)
        commit('setDeviceParamsSD', res.data.data)
        return res
      } catch (e) {
        throw new Error(e)
      }
    },
    async getDeviceLogListSD ({ commit }, data) {
      try {
        var res = await getDeviceLogListSD(data)
        commit('setDeviceLogListSD', res.data.data)
        return res
      } catch (e) {
        throw new Error(e)
      }
    },
    async getAreaListSD ({ commit }, data) {
      try {
        var res = await getAreaListSD(data)
        commit('setAreaListSD', res.data.data)
        return res
      } catch (e) {
        throw new Error(e)
      }
    }
  }
}
export default modules
